package br.ufrn.findabomb;

import br.ufrn.findabomb.controller.ServerFassade;
import br.ufrn.findabomb.model.Player;
import br.ufrn.findabomb.model.ServerResponse;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.view.View;

public class CadastroUsuario extends Activity{
	
	 protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.cadastro_usuario);

	        Button btCancelar = (Button) findViewById(R.id.btCancelar);
	        Button btCadastrar = (Button) findViewById(R.id.btCadastrar);
    
	        btCancelar.setOnClickListener(new OnClickListener() {
	        	 public void onClick(View v) {
	        		Intent intent = new Intent(CadastroUsuario.this, MainActivity.class);
	             	startActivity(intent);
	        	 }
	        });
	        
	        btCadastrar.setOnClickListener(new OnClickListener() {
	        	 public void onClick(View v) {

	     	        String etName = ((EditText) findViewById(R.id.etName)).getText().toString();;
	    	        String etId = ((EditText) findViewById(R.id.etId)).getText().toString();;
	    	        String etPasswd = ((EditText) findViewById(R.id.etPasswd)).getText().toString();;
	    	        String etConfirmarPasswd = ((EditText) findViewById(R.id.etConfirmarPasswd)).getText().toString();;
	    	        String etEmail = ((EditText) findViewById(R.id.etEmail)).getText().toString();
	        		 
	    	        ServerResponse sr = ServerFassade.createAccount(etId, etName, etEmail, etPasswd);
	    	        if (sr != null && sr.isSuccessfull()){
	    	        	Player p = (Player) sr.getData();
	    	        }
	    	        
	    	        
	        		Intent intent = new Intent(CadastroUsuario.this, MenuPrincipal.class);
	             	startActivity(intent);
	        	 }
	        });
    }    
    
	 public void test(int i, int b){
		 int test1 = 2;
		 int test3 = 3;
	 }
	 
	 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
}
